package com.p04.study.bean;

public class Player {
    /**
     * 记录球员的个数
     */
    private static int num;
    /**
     * 姓名
     */
    private  String name;
    /**
     * 年龄
     */
    private  int  age;

    /**
     * 构造函数
     * private 构造函数 防止别人创建对象，只能自己创建
     */
    private Player() {

    }

    private Player(String name, int age) {
        num++;
        this.name = name;
        this.age = age;
    }

    /**
     * 返回一个球员
     * @return
     */
    public static Player getPlayer(){
        //小于11个 就创建对象
        if(num<11){
            return new Player("球员"+(num+1),18);
        }else{
            //大于11个 则返回null
            return null;
        }
    }

    @Override
    public  String toString() {
        return "Player{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public void printTest(){
        this.test();
    }

    private void test(){
        System.out.println("test==>>");
    }
}
